package main

import (
	"fmt"
	"github.com/spf13/viper"
)

type ServerConfig struct {
	ServiceName string `mapstructure:"name"`
	Port int `mapstructure:"port"`
}

func main() {
	v := viper.New()
	// 文件的路径如何设置
	v.SetConfigFile("day16/config.yaml")
	if err := v.ReadInConfig(); err != nil {
		panic(err)
	}
	serverConfig := ServerConfig{}
	if err := v.Unmarshal(&serverConfig); err != nil{
		panic(err)
	}
	fmt.Println(serverConfig)
	fmt.Printf("%v", v.Get("name"))
}

func getEnv(env string) string {
	viper.AutomaticEnv()
	return viper.GetString(env)
}